
Unable to get an redirect url for forgot password in the development.log file
Reported by boddhisattva | March 7th, 2011 @ 10:45 AM
Hi,
Firstly , thank you very much for the Restful Authentication plugin. Since this plugin is no longer available via SVN, I am making use of the latest plugin found at https://github.com/technoweenie/restful-authentication.
I am using Ruby 1.8.7 and Rails 2.0.2 for project specific purposes. I hope I could use this plugin well( expecting it to be compatible ) with Rails 2.0.2. I have made the change in the plugin name. I am using rvm and rubygems 1.3.7. I am trying to implement the forgot password feature in a Rails application. The rails application that I have built is completely based on the tutorial in the url:-
http://railsonedge.blogspot.com/2008/03/rails-forum-restful-authent....
I was successfully able to implement Part 1 & 2 of the tutorial. I ran into issues when I tried to implement the Restful authentication with a) new user signing up with email notification to confirm the same b) implementing forgot password reature.
I am currently behind a proxy, so basically I made use of my development.log file to check If the email notifications works perfectly with the app.
With some slight modifications to the create method in users_controller.rb, I was able to get the Activate URL working for me to take care of signing in new users. This takes care of "a)".
The create method of this controller looks like this:-
def create
logout_keeping_session!
@user = User.new(params[:user])
#@user.register! if @user # && @user.valid? #we don't wont user to register. .. for 1st time login
@user.register! if @user && @user.valid? # this & immediate line one below.. still doesn't seem to work...!!
success = @user && @user.valid? # v want to sign in first or authenticate the same via mail...
#success = @user
if success && @user.errors.empty?
# redirect_back_or_default('/') redirect to create.html.erb
flash[:notice] = "Thanks for signing up! We're sending you an email with your activation code."
else
flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
render :action => 'new'
end
end
The log file which shoes the email is being sent is something like this:-
User Create (0.000421) INSERT INTO users
(salt
, activated_at
,
created_at
, crypted_password
,
remember_token_expires_at
, deleted_at
,
password_reset_code
, updated_at
,
activation_code
, remember_token
,
login
, email
, state
)
VALUES('e13da41c201cbb2156c347e06532e36b0a5e0036', NULL,
'2011-03-07 22:03:01', 'c4e09bedd96e988d1e0999cb0a4b9d725f25ed0b',
NULL, NULL, NULL, '2011-03-07 22:03:01',
'fe618a0b3f44b7667bfe087b11beae36a6598d6e', NULL, 'test8',
'test8@test.com', 'pending')
Sent mail:
Date: Mon, 7 Mar 2011 22:03:01 +0530 From: "Rails Forum Admin"
To: test8@test.com
Subject: [Rails Forum] New account information Please activate your
new account
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Your account has been created.
Username: test8 Password: 1234
Visit this url to activate your account:
http://localhost:3000/activate/fe618a0b3f44b7667bfe087b11beae36a659...
SQL (0.055377) COMMIT Rendering template within
layouts/application
Rendering users/create
Completed in 0.08722 (11 reqs/sec) | Rendering: 0.00362 (4%) | DB:
0.05725 (65%) | 200 OK [http://localhost/users]
Moving on to b)
I am unable to get the similar thing working for forget password. I am unable to identify where I am going wrong or where all I need to check to see if things are in place.
The code of forgot_password method that I implement in the same controller as above is:
def forgot_password
return unless request.post?
if @user = User.find_by_email(params[:user][:email])
@user.forgot_password
#@user.save # if I uncomment this I get the undefined method 'name' error. It says a password reset link has been sent to my mail(as a page redirection) but I don't any such url in my LOG file.
# in my development.log
#redirect_back_or_default('/')
flash[:notice] = "A password reset link has been sent to your email address"
else
flash[:alert] = "Could not find a user with that email address"
end
end
The error I get when uncommenting @user.save:
NoMethodError in UsersController#create
undefined method `name' for #<User:0xb6ee05f0>
I figured out that @user.save and @user.valid? don't seem to be working in Rails 2.0.2 for me.. I wonder how to rectify the same. Any suggestions?.
I verified the same with script/console. The error I get when I try to use these methods is as follows:-
mohnish@mohnish-desktop:~/rails_apps/railsprg_2/Mar11/4mar11/myforum$
script/console
Loading development environment (Rails 2.0.2)
ruby-1.8.7-p334 :001 > @user = User.new
=> # ruby-1.8.7-p334 :002 > @user.valid?
NoMethodError: undefined method `name' for
#<User:0xb713817c>
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:205:in `method_missing'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:392:in `send'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:392:in `validates_each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:391:in `each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:391:in `validates_each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:1004:in `call'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:1004:in `run_validations'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:998:in `each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:998:in `run_validations'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:962:in `valid_without_callbacks?'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:273:in `valid?'
from (irb):2
ruby-1.8.7-p334 :003 > @user.save
NoMethodError: undefined method `name' for
#<User:0xb713817c>
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:205:in `method_missing'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:392:in `send'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:392:in `validates_each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:391:in `each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:391:in `validates_each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:1004:in `call'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:1004:in `run_validations'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:998:in `each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:998:in `run_validations'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:962:in `valid_without_callbacks?'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:273:in `valid?'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/validations.rb:933:in `save_without_transactions'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in `transaction'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in `rollback_active_record_state!'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/transactions.rb:108:in `save'
from (irb):3ruby-1.8.7-p334 :004 > exit
May be If I can fix this, the app might work for me wrt forgot password also.
I have included the entire app code for reference. Kindly help me on this if feasible.
Thanks!!
Comments and changes to this ticket
-
boddhisattva March 7th, 2011 @ 10:53 AM
- no changes were found...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Restful Authentication Generator
This widely-used plugin provides a foundation for securely managing user
authentication:
* Login / logout
* Secure password handling
* Account activation by validating email
* Account approval / disabling by admin
* Rudimentary hooks for authorization and access control.
http://github.com/technoweenie/restful-authentication/tree